
#include "StringUtil.h"
#include <algorithm>
#include <sstream>
#include <tchar.h>

const StringUtil::String StringUtil::WHITE_SPACE = ( " \t\n\r" );
const StringUtil::String StringUtil::BLANK       = ( "" );

//Trim--------------------------------------------------------------------------
void StringUtil::Trim( StringUtil::String& str, bool removeLeft, bool removeRight )
{
    // Method (for trim start.  end is similar)
    // 1.) find the location of the first character that is not whitespace.
    // 2.) erase all characters up to that index.
    if ( removeLeft )
        str.erase( 0, str.find_first_not_of( StringUtil::WHITE_SPACE ) );
    if ( removeRight )
        str.erase( str.find_last_not_of( StringUtil::WHITE_SPACE ) + 1 );
}

//ToUpper-------------------------------------------------------------------
void StringUtil::ToUpper( StringUtil::String& str )
{
    // Iterate over the string, converting each character's case:
    std::transform( str.begin(), str.end(), str.begin(), toupper );
}

//ToLower-------------------------------------------------------------------
void StringUtil::ToLower( StringUtil::String& str )
{
    // Iterate over the string, converting each character's case:
    std::transform( str.begin(), str.end(), str.begin(), tolower );
}

//Find
int StringUtil::Find( const StringUtil::String& src, const StringUtil::String& substr )
{
    int index = 0;
    if ( ( index = src.find( substr, index ) ) != String::npos )
        return index;
    return -1;
}
